package com.evil.common.activiti.enums;

import com.evil.common.core.enums.BaseEnum;
import com.evil.common.family.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 超时触发类型
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@AllArgsConstructor
public enum OvertimeTriggerTypeEnum {

    /**
     * 超时触发类型，0:自定义时间, 1:表单值
     */
    CUSTOM_TIME(0, "自定义时间"),
    FORM_DATA(1, "表单值"),
    ;

    @Getter
    private final int id;
    @Getter
    private final String name;

    public static Optional<OvertimeTriggerTypeEnum> findById(Integer id) {
        if (null == id) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static OvertimeTriggerTypeEnum isExistById(Integer id) {
        return OvertimeTriggerTypeEnum.findById(id).orElseThrow(() ->
                new BusinessException(BaseEnum.ERROR_PARAMETER, "超时触发类型参数错误"));
    }
}
